package com.kantboot.api.google.translate.service.impl;

import com.kantboot.api.google.setting.ApiGoogleSetting;
import com.kantboot.api.google.translate.service.IGoogleTranslateService;
import com.kantboot.api.google.translate.util.GoogleTranslateUtil;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class GoogleTranslateServiceImpl implements IGoogleTranslateService {

    @Resource
    private ApiGoogleSetting apiGoogleSetting;

    @Override
    public String translateText(String sourceLanguageCode, String targetLanguage, String text) {
        try {
            return GoogleTranslateUtil.translateText(apiGoogleSetting.getGoogleProjectId(),
                    apiGoogleSetting.getGoogleCredJson(),
                    sourceLanguageCode,
                    targetLanguage,
                    text);
        }catch (Exception e){
            return translateText(sourceLanguageCode,targetLanguage,text);
        }
    }
}
